<template>
    <div class="newsinfo-header">
        <h1 class="title">{{newsinfo.title}}</h1>
        <p class="subtitle">
            <span>发表时间: {{ newsinfo.add_time }}</span>
            <span>点击：{{newsinfo.click}} 次</span>
        </p>
        <hr>
        <div class="content" v-html="newsinfo.content"></div>
        <comment :id="this.id"></comment>
    </div>    
</template>


<script>
import comment from '../subcomponents/Comment.vue'

export default {
    data() {
        return {
            id: this.$route.params.id,
            newsinfo: {}
        }    
    },
    created () {
        this.getNewsInfo();
    },
    methods: {
        getNewsInfo() {
            this.$http.get('api/getnew/' + this.id)
            .then(result => {
                if (result.body.status === 0) {
                    // 获取成功                    
                    this.newsinfo = result.body.message[0];
                    console.log(result.body)
                }
            })
        }
    },
    components: {
        'comment': comment
    }
}
</script>



<style lang="scss">
// 这里把 scoped 去掉，可以解决详情中显示的图片不全的问题
    .newsinfo-header {
        padding: 0 4px;

        .title {
            text-align: center;
            padding: 4px 0;
            // color: blue;
        }

        .subtitle {
            display: flex;
            justify-content: space-between
        }

        .content {
            // color: gray;
            img {
                width: 100%;
            }
        }
    }

</style>
